<template>
	<view>
		<view class="tab_nav">
			<view class="navTitle" v-for="(item,index) in navList" :key="index">
				<view :class="{'active':myAllindex === index}" @click="checked(index)">
					{{item.title}}
				</view>
			</view>
		</view>
		<!-- 店铺 -->
		<view class="" v-if="myAllindex==0">
			<view class="ffffff radius mainpadding margin_top" v-for="item in myAll[0].list.data" :key="item.id"
				@click="jumpdetail('/pages_shouye/mendianxq?id=',item.manystoreshop.id)">
				<view class="flexleft">
					<image class="listleftimg radius margin_right2" :src="item.manystoreshop.logo_text"></image>
					<view class="flexcolumnbet" style="height: 140rpx;">
						<view class="titletext hei_text bold">{{item.manystoreshop.name}}</view>
						<view class="flexleft">
							<u-icon name="man-add" color="#ff9341" size="16"></u-icon>
							<view class="xiaohuang margin_right margin_left1 strongtext">粉丝{{item.manystoreshop.gz_num}}个
							</view>
							<u-icon name="eye" color="#999" size="16"></u-icon>
							<view class="xiaohui margin_right margin_left1 strongtext">浏览{{item.manystoreshop.view_num}}次
							</view>
						</view>
					</view>
				</view>
				<view class="flexbetween margin_top2">
					<view class="flexleft">
						<u-icon name="map" color="#ff9341" size="18"></u-icon>
						<view class="xiaohui margin_left1 main_size yhxk" style="width: 500rpx;">
							{{item.manystoreshop.address}}
						</view>
					</view>
					<view class="xiaohuang main_size">{{returnKmUnit(Number(item.distance))}}</view>
				</view>
			</view>
		</view>
		<!-- 商品 -->
		<view class="mainpadding" v-if="myAllindex==1">
			<view class="flexbetween flex_wrap">
				<view class="spbox margin_top" v-for="item in myAll[1].list.data" :key="item.id" @click="tzspxq(item.goods.id,item.goods.goods_attr)">
					<image class="sptp1" :src="item.goods.image_text" mode=""></image>
					<view class="ffffff" style="padding: 25rpx 14rpx 30rpx;">
						<view class="xiankuan ershiba xiaohei">{{item.goods.title}}</view>
						<view class="flexbetween margin_top2">
							<view class="bigtext xiaohong fonweight">￥{{item.goods.goodsprice.price}}</view>
							<view class="smalltext xiaohui ">月售{{item.goods.sales}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				navList: [{
					index: 0,
					title: '店铺'
				}, {
					index: 1,
					title: "商品"
				}],
				myAll: [{ //店铺浏览记录
						url: "/api/shopcl/myShopViewIndex",
						page: 1,
						list: {
							data: []
						}
					},
					{ //商品浏览记录
						url: "/api/goodscl/myGoodsView",
						page: 1,
						list: {
							data: []
						}
					},
				],
				myAllindex: 0,
				lat: "",
				lng: "",
				cityid: "",
			}
		},
		onLoad() {
			let storagecity = uni.getStorageSync("storagecity") || null
			if (storagecity) {
				this.lat = storagecity.latitude
				this.lng = storagecity.longitude
				this.cityid = storagecity.cityid
			}
			this.getlistAll()
		},
		methods: {
			jumpdetail(url, id) {
				uni.navigateTo({
					url: url + id
				})
			},
			tzspxq(id,attr) {
				uni.navigateTo({
					url: '/pages_lianmengsc/shangpxq?id='+id+"&attr="+attr
				})
			},
			getlistAll() {
				this.myAll.forEach((item, index) => {
					if (item.url) {
						this.init(index)
					}
				})
			},
			init(index, isPage, page) {
				let _this = this
				let url = this.myAll[index].url
				let data = {
					page: this.myAll[index].page || 1,
					limit: 12,
				}
				if(index==0){
					this.$set(data,"lat",this.lat)
					this.$set(data,"lng",this.lng)
				}
				httpRequest.request(url, 'GET', data, false, false, true).then(res => {
					if (res.code == 1) {
						let resList = res.data;
						let dataList = this.myAll[index].list;
						if (isPage == true) {
							this.myAll[index].list.data = dataList.data.concat(resList.data);
						} else {
							this.myAll[index].list = res.data
							this.myAll[index].list.data = resList.data;
						}
					}
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			onReachBottom() {
				let _this = this;
				let list = _this.myAll[this.myAllindex].list;
				let page = _this.myAll[this.myAllindex].page;
				if (list.last_page <= page) {
					return false;
				}
				page++;
				_this.myAll[this.myAllindex].page = page;
				_this.init(this.myAllindex, true, page);
			},
			checked(index) {
				this.myAllindex = index
			},
			jumper(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.sptp1 {
		width: 100%;
		height: 330rpx;
		border-radius: 20rpx 20rpx 0rpx 0rpx;
	}

	.spbox {
		width: 48%;
		border-radius: 20rpx;
	}
</style>
<style lang="scss" scoped>
	.tab_nav {
		background-color: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		padding-bottom: 11rpx;
	}

	.tab_nav .navTitle {
		height: 76rpx;
		line-height: 76rpx;
		width: 100%;
		text-align: center;
		font-size: 30rpx;
		font-weight: bold;
		color: #999999;
	}

	.active {
		font-size: 30rpx;
		color: #333333;
		font-weight: bold;
		position: relative;
	}

	.active::after {
		content: "";
		position: absolute;
		width: 61rpx;
		height: 6rpx;
		background: #FFB800;
		border-radius: 9rpx;
		background-size: 100% 100%;
		left: 0rpx;
		right: 0rpx;
		bottom: 0rpx;
		margin: auto;
	}
</style>